from wwengine.registry import Registry, build_from_cfg

HANDS = Registry('hand')
BACKBONES = Registry('backbone')
NECKS = Registry('neck')
ROI_EXTRACTORS = Registry('roi_extractor')
SHARED_HEADS = Registry('shared_head')
HEADS = Registry('head')
LOSSES = Registry('loss')
MODELS = Registry('model')


def build(cfg, registry, default_args=None):
    return build_from_cfg(cfg, registry, default_args)

def build_hand(cfg):
    """Build hand."""
    return build(cfg, HANDS)

def build_backbone(cfg):
    """Build backbone."""
    return build(cfg, BACKBONES)


def build_neck(cfg):
    """Build neck."""
    return build(cfg, NECKS)


def build_roi_extractor(cfg):
    """Build roi extractor."""
    return build(cfg, ROI_EXTRACTORS)


def build_shared_head(cfg):
    """Build shared head."""
    return build(cfg, SHARED_HEADS)


def build_head(cfg):
    """Build head."""
    return build(cfg, HEADS)


def build_loss(cfg):
    """Build loss."""
    return build(cfg, LOSSES)


def build_model(cfg, train_cfg=None, test_cfg=None):
    """Build detector."""
    return build(cfg, MODELS, dict(train_cfg=train_cfg, test_cfg=test_cfg))
